<template>
	<view class="bg-img  flex align-center"
		style="height: 100vh; background-image: url('https://ossweb-img.qq.com/images/lol/web201310/skin/big10006.jpg');">
		<view class="login-wrap">
			<view class="cu-form-group ">
				<view class="title">用户名</view>
				<input v-model="user.mobile" placeholder="请输入手机号" ></input>
			</view>
			<view class="cu-form-group">
				<view class="title">密码</view>
				<input v-model="user.password" placeholder="请输入密码" ></input>
			</view>
			<button type="primary" @click="handleLogin">登陆</button>
			<view class="links">
				<view @tap="gotoForgetPassword">忘记密码？</view>
				<view>|</view>
				<view class="link-highlight" @tap="gotoRegistration">注册账号</view>
			</view>
		</view>
	</view>
</template>

<script>
import user from '../../store/user'
	export default {
		data() {
			return {
				user:{
					mobile:'',
					password:''
				}
			}
		},
		methods: {
			handleLogin(){
				if(!this.user.mobile || !this.user.password){
					uni.showToast({
						title:'请输入用户名或密码',
						icon:"error"
					})
					return
				}
				this.$ajax.post('/app/login',this.user).then(res => {
					console.log(res);
						if(res.code===0) {
							uni.showLoading({
								title: '加载中'
							});
							uni.reLaunch({
										url:'/pages/index/index'
									})
							let data = {
									userId:res.userId,
									token: res.token
								}
							this.$store.commit('user/initInfo',{...data})
							//存入本地
							uni.setStorage({
								key:'userInfo',
								data:data.userId
							})
						}
					}).finally(() => {
						uni.hideLoading()
					})
			},
			gotoRegistration: function() {
				uni.redirectTo({
					url: '/pages/registration/registration'
				});
			}
		}
		
	}
</script>

<style lang="scss" scoped>
	$color-primary: #58a0b4;
	page {
		height: 100%;
	}
	.login-wrap{
		margin: 0 auto;
		color:#ffffff;
		.cu-form-group{
			background-color: #16202a;
			opacity: 0.85;
		}
		button[type="primary"] {
			background-color: #303255;
			border-radius: 0;
			font-size: 34upx;
			margin-top: 60upx;
		}
		.links {
			text-align: center;
			margin-top: 40upx;
			font-size: 26upx;
			color: #999;
		
			view {
				display: inline-block;
				vertical-align: top;
				margin: 0 10upx;
			}
		
			.link-highlight {
				color: $color-primary;
			}
		}
	}
	.cu-form-group .title {
		min-width: calc(4em + 15px);
	}
	
</style>
